var PENDING = false;
$.fn.serializeObject = function(){
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toGMTString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}
function frotendrequest(_option) {
    var option = {
        url: null,
        data: null,
        datatype: "json",
        callback: null
    };
    if (_option)
        $.each(_option, function(index, value) {
            option[index] = value;
        });
    if (option.datatype.toUpperCase() === 'JSON') {
        option.data.ajaxtype = 'json';
    }
    return {
        call: function(_url, _data, _callback) {
            if (PENDING === true)
                return;
            if (_url)
                option.url = _url;
            if (_data)
                option.data = _data;
            if (_callback)
                option.callback = _callback;
            PENDING = true;
            jQuery.ajax({
                type: "POST",
                //cache:false,
                //timeout:10000,
                data: option.data,
                dataType: option.datatype,
                url: option.url,
                success: function(data_result) {
                    PENDING = false;
                    if (typeof(option.callback) === 'function')
                        option.callback(data_result);
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    PENDING = false;
                    WarningMessage("Sorry. Your request could not be completed.<br/> Please check your input data and try again.");
                }
            });
        }
    };
}
function NoticeMessage(msg){
    $('#NoticeMessage .dialog-modal-content').html(msg);
    $('#NoticeMessage,.dialog-modal-marker').fadeIn();
}
function WarningMessage(msg){
    $('#WarningMessage .dialog-modal-content').html(msg);
    $('#WarningMessage,.dialog-modal-marker').fadeIn();
}
function CloseMessage(){
    $('.dialog-modal-dialog,.dialog-modal-marker').fadeOut();
}

function newcontactus(){
	if(PENDING)return;
	
	if( $('#frmcontactus').validationEngine('validate') === false)return false;
	var Params = $('#frmcontactus').serializeObject();
	PENDING=true;
	jQuery.ajax({
		type: "POST",
		//cache:false,
		//timeout:10000,
		data: {
			Params:Params
		},
		dataType: 'json',
		url: '/home/addcontacus',
		success: function(data_result) {
			PENDING = false;
			if(data_result.result>0){
				document.frmcontactus.reset();
			}
			NoticeMessage(data_result.message);
			
		},
		error: function(xhr, ajaxOptions, thrownError) {
			PENDING = false;
			NoticeMessage('Sorry. Your request could not be completed.<br/> Please check your input data and try again.');
		}
	});
}
$(document).ready(function(){
	if($("#frmcontactus").length>0)
		$("#frmcontactus").validationEngine(); 
	if($("img.lazy").length>0)
		$("img.lazy").lazyload();
	try {
		if ($("a.swipebox").length > 0) {
			$("a.swipebox").swipebox({
				useCSS: true, // false will force the use of jQuery for animations
				//hideBarsDelay: 0 // 0 to always show caption and action bar
			});
		}
	} catch (e) {
	}
	$('.'+active_menu).addClass('active');
	$('.go-to-top').click(function(){
		$('body,html').animate({scrollTop: 0}, 1000);
	});
});
try {
	$(window).scroll(function () {
		var st = $(window).scrollTop();
		if(st>200){
			$('.go-to-top').fadeIn();
		}else{
			$('.go-to-top').fadeOut();
			
		}
	});
	
} catch (e) {
}